import React, { FC } from 'react';
import { Switch, Route, useLocation } from 'react-router-dom';
import FullPage from '@/pages/Fullpage';
import Console from './Console';
import _ from 'lodash';
import { menuConfig } from '@/config/menuConfig';

// eslint-disable-next-line object-curly-spacing
const App: FC = () => {
  const location = useLocation();
  const pathName = _.split(location.pathname, '/');
  const renderRouter: any = (data) => {
    return _.map(data, (item, key) => {
      if (item.children) {
        return renderRouter(item.children);
      }
      if (_.isArray(item.path)) {
        return renderRouter(item.path);
      }
      return (
        <Route
          key={'/console/' + item.path}
          exact={item.exact}
          path={'/console/' + item.path}
          component={item.component}
        ></Route>
      );
    });
  };
  return (
    <Switch>
      <Route
        path="/console"
        render={() => (
          <Console>
            <Switch>{renderRouter(menuConfig[pathName[2]])}</Switch>
          </Console>
        )}
      ></Route>
      <Route path="/" component={FullPage}></Route>
    </Switch>
  );
};

export default App;
